#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int n,a[110],l,r,k;
void solve()
{
	cin>>n>>l>>r>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	ll sum=0,num=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]>r||sum>k) break;
		if(a[i]>=l&&a[i]<=r&&sum+a[i]<=k) sum+=a[i],num++;
	}
	cout<<num<<'\n';
	
}

int main()
{
	close();
	int T; cin>>T;
	while (T--) solve();
	return 0;
}